package com.fasteat.menu.controller;


import com.fasteat.common.entity.Result;
import com.fasteat.menu.entity.ReportMessage;
import com.fasteat.menu.entity.ReportType;
import com.fasteat.menu.entity.vo.DisposeReportVo;
import com.fasteat.menu.entity.vo.ReportSearchMap;
import com.fasteat.menu.service.ReportService;
import com.fasteat.menu.service.impl.ReportServiceImpl;
import com.fasteat.menu.util.UpdateProxy;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author run
 * @since 2021-01-19
 */
@Api(tags = "举报反馈相关的接口")
@CrossOrigin
@RestController
@RequestMapping("/fasteat/report")
public class ReportController {

    @Autowired
    private ReportService reportService;

    @Autowired
    private UpdateProxy updateProxy;

    @PostMapping("/user/get/{page}/{size}")
    @ApiOperation("分页获取(我的)举报信息")
    public Result searchMyReport(@RequestBody @ApiParam("searchMap") ReportSearchMap searchMap
                                    ,@PathVariable(value = "page") Integer page
                                    ,@PathVariable(value = "size") Integer size){
        return Result.success().data(reportService.searchReportMessage(searchMap,page,size,false));
    }

    @PostMapping("/user/get")
    @ApiOperation("获取(我的)全部举报信息")
    public Result searchAllMyReport(@RequestBody @ApiParam("searchMap") ReportSearchMap searchMap){
        return Result.success().data(reportService.searchReportMessage(searchMap,false));
    }


    @PutMapping("/user/")
    @ApiOperation("修改(我的)举报信息")
    public Result updateMyReport(@Valid @RequestBody @ApiParam(name = "举报信息对象",value = "reportMessage") ReportMessage reportMessage){
        return ((ReportService)updateProxy.bind(new ReportServiceImpl()).getProxyInstance()).updateReportMessage(reportMessage)
                ? Result.success("修改成功") : Result.error("修改失败");
    }

    @PostMapping("/user/")
    @ApiOperation("发布举报信息")
    public Result createMenuReport(@Valid @RequestBody @ApiParam(name = "举报信息对象",required = true,value = "reportMessage")
                                           ReportMessage reportMessage){
        return reportService.createReportMessage(reportMessage)
                ? Result.success("发布成功") : Result.error("发布失败");
    }

    @DeleteMapping("/user/{id}")
    @ApiOperation("撤销（我的）举报")
    public Result deleteMyReport(@PathVariable(value = "id") String reportMessageId){
        return reportService.deleteReportMessage(reportMessageId,false)
                ? Result.success("撤销成功") : Result.error("撤销失败");
    }



    /**
     * 后台接口
     * @param page
     * @param size
     * @return
     */
    @PostMapping("/backstage/reportMessage/{page}/{size}")
    @ApiOperation("分页获取平台举报信息（后台接口）")
    public Result searchPlatformReport(@RequestBody @ApiParam("searchMap") ReportSearchMap searchMap
                                        , @PathVariable(value = "page") Integer page
                                        , @PathVariable(value = "size") Integer size){
        return Result.success().data(reportService.searchReportMessage(searchMap,page,size,true));
    }

    /**
     * 后台接口
     * @return
     */
    @PostMapping("/backstage/reportMessage")
    @ApiOperation("获取平台所有举报信息（后台接口）")
    public Result searchAllPlatformReport(@RequestBody @ApiParam("searchMap") ReportSearchMap searchMap){
        return Result.success().data(reportService.searchReportMessage(searchMap,true));
    }

    @GetMapping("/user/reportType")
    @ApiOperation("获取举报类别列表（用户/后台）")
    public Result getReportType(){
        return Result.success().data(reportService.searchReportType());
    }

    /**
     * 后台接口
     * @param reportMessageId
     * @return
     */
    @DeleteMapping("/backstage/reportMessage/{id}")
    @ApiOperation("撤销举报信息（后台接口）")
    public Result deleteUserReport(@PathVariable(value = "id") String reportMessageId){
        return reportService.deleteReportMessage(reportMessageId,true)
                ? Result.success("撤销成功") : Result.error("撤销失败");
    }

    /**
     * 后台接口
     * @return
     */
    @PutMapping("/backstage/reportMessage")
    @ApiOperation("处理举报信息（后台接口）")
    public Result disposeReport(@RequestBody @ApiParam(value = "disposeReportVo")DisposeReportVo disposeReportVo){
        return reportService.disposeReport(disposeReportVo)
                ? Result.success("处理成功") : Result.error("处理失败");
    }

    /**
     * 后台接口
     * @param reportType
     * @return
     */
    @PostMapping("/backstage/reportType")
    @ApiOperation("创建举报类别（后台接口）")
    public Result createReportType(@Valid @RequestBody @ApiParam(name = "举报类别对象",required = true,value = "reportType") ReportType reportType){
        return reportService.createReportType(reportType)
                ? Result.success("创建成功") : Result.error("创建失败");
    }

    /**
     * 后台接口
     * @param reportTypeId
     * @return
     */
    @DeleteMapping("/backstage/reportType/{id}")
    @ApiOperation("删除举报类别（后台接口）")
    public Result deleteReportType(@PathVariable(value = "id") String reportTypeId){
        return reportService.deleteReportType(reportTypeId)
                ? Result.success("删除成功") : Result.error("删除失败");
    }


    /**
     * 后台接口
     * @param reportType
     * @return
     */
    @PutMapping("/backstage/reportType")
    @ApiOperation("修改举报类别（后台接口）")
    public Result updateReportType(@Valid @RequestBody @ApiParam(name = "举报类别对象",value = "reportType") ReportType reportType){
        return reportService.updateReportType(reportType)
                ? Result.success("修改成功") : Result.error("修改失败");
    }
}

